package com.ruoyi.system.controller;

import java.util.List;

import com.ruoyi.system.domain.CsBuyRecordVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.CsBuyRecord;
import com.ruoyi.system.service.ICsBuyRecordService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 物品库存Controller
 *
 * @author ruoyi
 * @date 2025-10-04
 */
@Controller
@RequestMapping("/system/record")
public class CsBuyRecordController extends BaseController {
    private String prefix = "system/record" ;

    @Autowired
    private ICsBuyRecordService csBuyRecordService;

    @GetMapping()
    public String record() {
        return prefix + "/record" ;
    }

    /**
     * 查询物品库存列表
     */
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(CsBuyRecord csBuyRecord) {
        startPage();
        List<CsBuyRecord> list = csBuyRecordService.selectCsBuyRecordList(csBuyRecord);
        return getDataTable(list);
    }

    /**
     * 导出物品库存列表
     */
    @Log(title = "物品库存", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(CsBuyRecord csBuyRecord) {
//        List<CsBuyRecordVo> list = csBuyRecordService.selectCsBuyRecordList(csBuyRecord);
//        ExcelUtil<CsBuyRecordVo> util = new ExcelUtil<CsBuyRecordVo>(CsBuyRecordVo.class);
//        return util.exportExcel(list, "物品库存数据");
        return AjaxResult.success(csBuyRecordService.selectCsBuyRecordList(csBuyRecord));
    }

    /**
     * 新增物品库存
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add" ;
    }

    /**
     * 新增保存物品库存
     */
    @Log(title = "物品库存", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(CsBuyRecord csBuyRecord) {
        return toAjax(csBuyRecordService.insertCsBuyRecord(csBuyRecord));
    }

    /**
     * 修改物品库存
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap) {
        CsBuyRecord csBuyRecord = csBuyRecordService.selectCsBuyRecordById(id);
        mmap.put("csBuyRecord", csBuyRecord);
        return prefix + "/edit" ;
    }

    /**
     * 修改保存物品库存
     */
    @Log(title = "物品库存", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(CsBuyRecord csBuyRecord) {
        return toAjax(csBuyRecordService.updateCsBuyRecord(csBuyRecord));
    }

    /**
     * 删除物品库存
     */
    @Log(title = "物品库存", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(csBuyRecordService.deleteCsBuyRecordByIds(ids));
    }
}
